package com.dq.Service.Impl;

import com.alibaba.fastjson2.util.DateUtils;
import com.dq.Mapper.SubworkMapper;
import com.dq.Pojo.Subwork;
import com.dq.Service.SubworkService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import net.sf.jsqlparser.expression.DateTimeLiteralExpression;
import org.apache.poi.ss.usermodel.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.UUID;

@Service
public class SubworkServiceImpl implements SubworkService {
    @Autowired
    private SubworkMapper subworkMapper;

    @Override
    public List<Subwork> find(Integer id) {
        return subworkMapper.find(id);
    }

    @Override
    public void add(Subwork subwork) {
        Date date=new Date();
        subwork.setSubtime(DateUtils.toString(date));
        subworkMapper.add(subwork);
    }

    @Override
    public Subwork findByid(Integer homeworkId, Integer stuId) {
       return subworkMapper.findByid(homeworkId,stuId);
    }

    @Override
    public void update(Subwork subwork) {
        subworkMapper.update(subwork);
    }

    @Override
    public Subwork review(Integer homeworkId, Integer stuId) {
        return subworkMapper.review(homeworkId,stuId);
    }

    @Override
    public PageInfo<Subwork> getworkgrade(Integer pageNum, Integer pageSize, Integer stuId,Integer courseId,String type) {
        PageHelper.startPage(pageNum,pageSize);
        List<Subwork> subworkList=subworkMapper.getworkgrade(stuId,courseId,type);
        PageInfo<Subwork> pageInfo=new PageInfo<>(subworkList);
        return pageInfo;
    }

    @Override
    public PageInfo<Subwork> getgradeAll(Integer pageNum, Integer pageSize, Integer courseId,Integer classId, String stuId, String type) {
        PageHelper.startPage(pageNum,pageSize);
        List<Subwork> subworkList=subworkMapper.getgradeAll(courseId,classId,stuId,type);
        PageInfo<Subwork> pageInfo=new PageInfo<>(subworkList);
        return pageInfo;
    }
}
